package com.drop.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.drop.dao.OrderShowDao;
import com.drop.entity.Order;
@Repository
public class OrderShowDaoImp implements OrderShowDao{
	private SessionFactory sessionFactory;

	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public Session getSession(){
		return sessionFactory.getCurrentSession();
	}


	@Override
	public List<Order> getOrder(int userid, int state) {
		// TODO Auto-generated method stub
		String hql="from Order o where o.user.userId=? and o.state.stateId=?";
		
		return (List<Order>)getSession().createQuery(hql).setParameter(0, userid).setParameter(1, state).list();
	}

	@Override
	public List<Order> getAllorder(int userid) {
		// TODO Auto-generated method stub
		String hql="from Order o where o.user.userId=?";
		return (List<Order>)getSession().createQuery(hql).setParameter(0, userid).list();
	}

	@Override
	public Order getOrderById(int orderid) {
		// TODO Auto-generated method stub
		return (Order) getSession().get(Order.class, orderid);
	}

}
